package br.com.rafael.gestorinvestimentos.DAO;


import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import br.com.rafael.gestorinvestimentos.model.Portfolio;

/**
 * author Rafael
 23/07/2007
 */
public class PortfolioDAO { 
	private Session session;
	
	public PortfolioDAO(Session session){
		this.session = session;
	}	
	
	public void insert (Portfolio portfolio){
		this.session.save(portfolio);
	}
	
	public void update (Portfolio portfolio){
		this.session.update(portfolio);
	}
	
	public void delete (Portfolio portfolio){
		this.session.delete(portfolio);
	}
	
	public Portfolio getPortfolio (int id){
		return (Portfolio) session.load(Portfolio.class, id);
	
	}
	
	public Portfolio getPortfolio (String nome){
		Query q = this.session.createQuery("from Portfolio as portfolio where portfolio.nome = :portfolioNome").setParameter("portfolioNome", nome);
		return (Portfolio) q.uniqueResult();
	}
	
	public List getList (){
		return this.session.createCriteria(Portfolio.class).list();
	}
}